//
//  VoteHomepageCell.m
//  meiyinxiang
//
//  Created by 媒印象 on 04/12/2017.
//  Copyright © 2017 hbjApple. All rights reserved.
//

#import "VoteHomepageCell.h"
#import <UIImageView+WebCache.h>
@interface VoteHomepageCell()
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *voteIdLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *voteCountLabel;
@property (weak, nonatomic) IBOutlet UIButton *voteBtn;

@end

@implementation VoteHomepageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.layer.cornerRadius = 5;
    self.layer.masksToBounds = YES;
    [self addImgTapGes];
}
- (void)setModel:(VoteViewModel *)model{
    _model = model;
    self.iconImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.iconImageView.layer.masksToBounds = YES;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:[UIImage imageNamed:@"voteDdefualphoto"]];
    self.voteIdLabel.text = model.voteid;
    self.nameLabel.text = model.name;
    self.voteCountLabel.text = model.vote_num;
    
}
- (void)addImgTapGes{
    //点击查看照片
    UITapGestureRecognizer *tapImg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImgAct)];
    [self.iconImageView addGestureRecognizer:tapImg];
    self.iconImageView.userInteractionEnabled = YES;
}
- (void)tapImgAct{
    HMPhotoBrowserController *photoBrowser =   [HMPhotoBrowserController photoBrowserWithSelectedIndex:0 urls:@[self.model.image] parentImageViews:@[self.iconImageView]];
    [self.mSuperVC presentViewController:photoBrowser animated:YES completion:nil];
}

- (IBAction)voteBtn:(id)sender {
    
[self.model voteWithResult:^(BOOL isSucess) {
       
}];
}
+ (VoteHomepageCell *)loadNibWithHomepageCell{
    UINib *nib = [UINib nibWithNibName:@"VoteHomepageCell" bundle:[NSBundle mainBundle]];
    return [[nib instantiateWithOwner:nil options:nil] lastObject];
}
@end
